package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.dto.FamilyMemberDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.dto.member.DeviceDataListByDayDto;
import com.zzyl.nursing.mapper.DeviceDataMapper;
import com.zzyl.nursing.vo.member.HourlyDataVO;
import com.zzyl.nursing.dto.member.QueryDevicePropertyStatusDto;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.FamilyMemberElderVo;
import com.zzyl.nursing.vo.FamilyMemberVo;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.member.DevicePropertyStatusVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;


    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult add(@RequestBody FamilyMemberDto dto){
        familyMemberService.addFamilyMember(dto);
        return success();
    }

    @GetMapping("/my")
    @ApiOperation("查询当前登录用户的家人")
    public AjaxResult myFamily(){
        List<FamilyMemberVo> myFamilyMembers = familyMemberService.getMyFamilyMembers();
        return success(myFamilyMembers);
    }

    @GetMapping("/list-by-page")
    @ApiOperation("查询当前登录用户的家人")
    public AjaxResult list(){
        startPage();
        List<FamilyMemberElderVo> familyMemberElderVos = familyMemberService.listByPage();
        return success(familyMemberElderVos);
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查看健康数据")
    public AjaxResult viewHealthData(@RequestBody QueryDevicePropertyStatusDto dto){
        Map<String, Object> vo = familyMemberService.viewHealthData(dto);
        return success(vo);
    }

    @Autowired
    private DeviceDataMapper deviceDataMapper;

    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("查询设备数据指标(按天)")
    public AjaxResult queryDeviceDataListByDay(DeviceDataListByDayDto dto){
        List<HourlyDataVO> result = familyMemberService.queryDeviceDataListByDay(dto);
        return success(result);
    }

    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("查询设备数据指标(按周)")
    public AjaxResult queryDeviceDataListByWeek(DeviceDataListByDayDto dto){
        List<HourlyDataVO> result = familyMemberService.queryDeviceDataListByWeek(dto);
        return success(result);
    }

    @DeleteMapping("/deleteById")
    @ApiOperation("解绑")
    public AjaxResult deleteById( Long id){
        familyMemberService.deleteById( id);
        return success();
    }







}
